
#include"game.h"
void menu(){
    printf("*****************\n");
    printf("****1.开始游戏*****\n");
    printf("****0.退出游戏*****\n");
    printf("*****************\n");
}
void game(){
    char board[ROW][COL]={0};
    int ret=0;
    initboard(board,ROW,COL);
    displayboard(board,ROW,COL);
    while(1){
        playermove(board,ROW,COL);
        displayboard(board,ROW,COL);
        ret = iswin(board,ROW,COL);
        if(ret!='C'){
            break;
        }
        computermove(board,ROW,COL);
        displayboard(board,ROW,COL);
        ret = iswin(board,ROW,COL);
        if(ret!='C'){
            break;
        }
    }
    if(ret == 'X'){
        printf("玩家赢\n");
    }
    else if(ret == 'Y'){
        printf("电脑赢\n");
    }
    else{
        printf("平局\n");
    }
}
void test(){
    int input=0;
    srand((unsigned int)time(NULL));
    do{
        menu();
        printf("请选择:\n");
        scanf("%d",&input);
        switch(input){
            case 1:
                game();
                break;
            case 0:
                printf("退出游戏\n");
                break;
            default:
                printf("输入错误\n");
                break;
        }
    }
    while(input);
}
int main(){
    test();
    return 0;
}